<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>

    <script>
        $(function () {
            var placeId;
            //获取攻略推荐推荐
            $.get('/travels/commends', {type: 3, pageSize: 1}, function (data) {
                if (data.list.length > 0) {
                    $(".commend").renderValues(data.list[0]);
                    //给a链接绑定事件
                    $(".commend a[data-url]").click(function () {
                        var url = $(this).data('url');
                        var id = $(this).data('tid');
                        window.location.href = url + id;
                    })
                }
            })
            //获取所有推荐大攻略
            $.get('/strategies', {state: 1, pageSize: 0}, function (data) {
                $(".strategyCommend").renderValues(data);
                //给a链接绑定事件
                $(".strategyCommend a[data-url]").click(function () {
                    var url = $(this).data('url');
                    var id = $(this).data('sid');
                    window.location.href = url + id;
                })
            })
            //获取推荐地区
            $.get('/regions', {state: 1}, function (data) {
                var html = "";
                var contentHtml = "";
                $.each(data, function (index, ele) {
                    html += '<li class="nav-item"><a data-id="' + ele.id + '" class="nav-link" id="pills-'
                        + ele.id + '-tab" data-toggle="pill" href="#pills-' + ele.id + '">'
                        + ele.name + '</a></li>';
                    contentHtml += '<div class="tab-pane fade" id="pills-' + ele.id + '"></div>';
                })
                //导航头
                $("#pills-tab").append(html);
                //内容
                $("#pills-tabContent").append(contentHtml);
                //绑定点击事件
                $(".nav-link").click(function () {
                    //获取地区的id
                    var id = $(this).data("id");
                    //设置到全局变量中
                    placeId = id;
                    if (placeId) {
                        //重置分页数据
                        currentPage.val(2);
                        pages = 2;//总页数
                        $.ajax({
                            dataType: 'html',
                            data: {
                                pageSize: pageSize
                            },
                            url: '/regions/' + id + '/strategies',
                            success: function (data) {
                                //获取地区对应的div内容
                                $("#pills-" + id).html(data);
                            }
                        })
                    }
                })
            })
            var pageSize = $("#pageSize").val();
            //获取当前页的input框
            var currentPage = $("#currentPage");
            //设置总游记数量
            var pages = 2;
            //设置用于存储所有游记的数组
            var strategyData = [];
            //封装成一个query方法
            function query() {
                //获取当前页的值
                var currentPageValue = currentPage.val();
                $.ajax({
                    dataType: 'json',
                    data: {
                        currentPage: currentPageValue,
                        pageSize: pageSize
                    },
                    url: '/regions/' + placeId + '/strategies',
                    success: function (data) {
                        var content = "";
                        $.each(data.list, function (index, ele) {
                            content += '<div class="col-6 mb"><a href="../strategyCatalogs.html?strategyId="' + ele.id + '>'
                                + '<img class="float-left " src="' + ele.coverUrl + '">'
                                + '<div class="classify-text"><span>' + ele.title + '</span>'
                                + '<p>0人收藏</p></div></a></div>'
                        })
                        //把获取到的攻略数据拼接到div内容后面
                        $(".classify").append(content);
                        //将当前页加一
                        currentPage.val(parseInt(currentPageValue) + 1);
                        //设置总页数的值
                        pages = data.pages;
                    }
                })
            }

            //增加一个滚动事件
            $(window).scroll(function () {
                //页面的高度加上卷上去的高度大于等于整个文档的高度
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    //获取当前页的值
                    var currentPageValue = currentPage.val();
                    //判断是否是最后一页
                    if (currentPageValue <= pages) {
                        query();
                    } else {//提示用户已到底
                        $(document).dialog({
                            type: "notice",
                            infoText: "已经到底了",
                            autoClose: 1000
                        })
                    }
                }
            })

        })
    </script>
</head>

<body>
<input type="hidden" name="currentPage" id="currentPage" value="2">
<input type="hidden" name="pageSize" id="pageSize" value="8">
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="找攻略">
            </div>
        </div>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <a href="javascript:;" data-url="travelContent.html?id=" render-attr="data-tid=travel_id">
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>
        <hr>
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a href="javascript:;" data-url="strategyCatalogs.html?strategyId=" render-attr="data-sid=list.id">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>

</div>
</div>


</body>

</html>